home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / elv18src.zip / opts.c < prev    next >
C/C++ Source or Header  |  1994-01-13  |  23KB  |  1,104 lines

  1. /* opts.c */
  2.  
  3. /* Author:
  4.  *    Steve Kirkendall
  5.  *    14407 SW Teal Blvd. #C
  6.  *    Beaverton, OR 97005
  7.  *    kirkenda@cs.pdx.edu
  8.  */
  9.  
  10.  
  11. /* modified by TJH and FEB to port to VMS */
  12.  
  13.  
  14. /* This file contains the code that manages the run-time options -- The 
  15.  * values that can be modified via the "set" command.
  16.  */
  17.  
  18. #include "config.h"
  19. #include "vi.h"
  20. #include "ctype.h"
  21. #include <stdio.h>
  22. #if VMS
  23. # include <ssdef.h>
  24. # include <iodef.h>
  25. # include <descrip.h>
  26. # include <tt2def.h>
  27. #endif
  28. #ifndef NULL
  29. #define NULL (char *)0
  30. #endif
  31.  
  32. /* maximum width to permit for strings, including ="" */
  33. #define MAXWIDTH 20
  34.  
  35. /* These are the default values of all options */
  36. char    o_autoindent[1] =    {FALSE};
  37. char    o_autoprint[1] =    {TRUE};
  38. char    o_autotab[1] =        {TRUE};
  39. char    o_autowrite[1] =     {FALSE};
  40. char    o_columns[3] =        {80, 32, ~0};
  41. char    o_directory[30] =    TMPDIR;
  42. char    o_edcompatible[1] =    {FALSE};
  43. char    o_equalprg[80] =    {"fmt"};
  44. char    o_errorbells[1] =    {TRUE};
  45. char    o_exrefresh[1] =    {TRUE};
  46. char    o_ignorecase[1] =    {FALSE};
  47. char    o_keytime[3] =        {2, 0, 50};
  48. char    o_keywordprg[80] =    {KEYWORDPRG};
  49. char    o_lines[3] =        {25, 2, 96};
  50. char    o_list[1] =        {FALSE};
  51. char    o_number[1] =        {FALSE};
  52. char    o_readonly[1] =        {FALSE};
  53. char    o_remap[1] =        {TRUE};
  54. char    o_report[3] =        {5, 1, 127};
  55. char    o_scroll[3] =        {12, 1, 127};
  56. char    o_shell[60] =        SHELL;
  57. char    o_shiftwidth[3] =    {8, 1, ~0};
  58. char    o_sidescroll[3] =    {8, 1, 40};
  59. char    o_sync[1] =        {NEEDSYNC};
  60. char    o_tabstop[3] =        {8, 1, 40};
  61. char    o_term[30] =        "?";
  62. char    o_flash[1] =        {TRUE};
  63. char    o_warn[1] =        {TRUE};
  64. char    o_wrapscan[1] =        {TRUE};
  65.  
  66. #ifndef CRUNCH
  67. char    o_beautify[1] =        {FALSE};
  68. char    o_exrc[1] =        {FALSE};
  69. char    o_mesg[1] =        {TRUE};
  70. char    o_more[1] =        {TRUE};
  71. char    o_nearscroll[3] =    {15, 0, ~0};
  72. char    o_newfile[1] =        {FALSE};
  73. char    o_novice[1] =        {FALSE};
  74. char    o_optimize[1] =        {FALSE};
  75. char    o_prompt[1] =        {TRUE};
  76. char    o_taglength[3] =    {0, 0, 30};
  77. char    o_tags[256] =        {"tags"};
  78. char    o_terse[1] =        {FALSE};
  79. char    o_window[3] =        {0, 0, ~0};
  80. char    o_wrapmargin[3] =    {0, 0, ~0};
  81. char    o_writeany[1] =        {FALSE};
  82. #endif
  83.  
  84. #ifndef NO_ERRLIST
  85. char    o_cc[30] =        {CC_COMMAND};
  86. char    o_make[30] =        {MAKE_COMMAND};
  87. #endif
  88.  
  89. #ifndef NO_CHARATTR
  90. char    o_charattr[1] =        {FALSE};
  91. #endif
  92.  
  93. #ifndef NO_DIGRAPH
  94. char    o_digraph[1] =        {FALSE};
  95. char    o_flipcase[80]
  96. # ifdef CS_IBMPC
  97.     = {"\207\200\201\232\202\220\204\216\206\217\221\222\224\231\244\245\233\235"}
  98. # endif
  99. # ifdef CS_LATIN1
  100.     /* initialized by initopts() */
  101. # endif
  102.     ;
  103. #endif
  104.  
  105. #ifndef NO_SENTENCE
  106. char    o_hideformat[1] =    {FALSE};
  107. #endif
  108.  
  109. #ifndef NO_EXTENSIONS
  110. char    o_inputmode[1] =    {FALSE};
  111. char    o_ruler[1] =        {FALSE};
  112. #endif
  113.  
  114. #ifndef NO_MAGIC
  115. char    o_magic[1] =        {TRUE};
  116. #endif
  117.  
  118. #ifndef NO_MODELINES
  119. char    o_modelines[1] =    {FALSE};
  120. #endif
  121.  
  122. #ifndef NO_SENTENCE
  123. char    o_paragraphs[30] =    "PPppIPLPQP";
  124. char    o_sections[30] =    "NHSHSSSEse";
  125. #endif
  126.  
  127. #if MSDOS
  128. char    o_pcbios[1] =        {TRUE};
  129. char    o_controlz[1] =        {TRUE};
  130. #endif
  131.  
  132. #if OS2
  133. char    o_viomode[1] =        {FALSE};
  134. #endif
  135.  
  136. #ifndef NO_SHOWMATCH
  137. char    o_showmatch[1] =    {FALSE};
  138. #endif
  139.  
  140. #ifndef    NO_SHOWMODE
  141. char    o_smd[1] =        {FALSE};
  142. #endif
  143.  
  144. #ifndef NO_TAGSTACK
  145. char    o_tagstack[1] =        {TRUE};
  146. #endif
  147.  
  148. #ifdef DEBUG
  149. char    o_slowmacro[1] =     {FALSE};
  150. #endif
  151.  
  152.  
  153.  
  154. /* The following describes the names & types of all options */
  155. #define BOOL    0
  156. #define    NUM    1
  157. #define    STR    2
  158. #define SET    0x01    /* this option has had its value altered */
  159. #define CANSET    0x02    /* this option can be set at any time */
  160. #define RCSET    0x06    /* this option can be set in a .exrc file only */
  161. #define NOSAVE    0x0a    /* this option should never be saved by mkexrc */
  162. #define MR    0x20    /* does this option affect the way text is displayed? */
  163. struct
  164. {
  165.     char    *name;    /* name of an option */
  166.     char    *nm;    /* short name of an option */
  167.     char    type;    /* type of an option */
  168.     char    flags;    /* boolean: has this option been set? */
  169.     char    *value;    /* value */
  170. }
  171.     opts[] =
  172. {
  173.     /* name            type    flags        value */
  174.     { "autoindent",    "ai",    BOOL,    CANSET,        o_autoindent    },
  175.     { "autoprint",    "ap",    BOOL,    CANSET,        o_autoprint    },
  176.     { "autotab",    "at",    BOOL,    CANSET,        o_autotab    },
  177.     { "autowrite",    "aw",    BOOL,    CANSET,        o_autowrite    },
  178. #ifndef CRUNCH
  179.     { "beautify",    "bf",    BOOL,    CANSET,        o_beautify    },
  180. #endif
  181. #ifndef NO_ERRLIST
  182.     { "cc",        "cc",    STR,    CANSET,        o_cc        },
  183. #endif
  184. #ifndef NO_CHARATTR
  185.     { "charattr",    "ca",    BOOL,    CANSET|MR,    o_charattr    },
  186. #endif
  187.     { "columns",    "co",    NUM,    SET|NOSAVE|MR,    o_columns    },
  188. #if MSDOS
  189.     { "controlz",    "z",    BOOL,    CANSET,        o_controlz    },
  190. #endif
  191. #ifndef NO_DIGRAPH
  192.     { "digraph",    "dig",    BOOL,    CANSET,        o_digraph    },
  193. #endif
  194.     { "directory",    "dir",    STR,    RCSET,        o_directory    },
  195.     { "edcompatible","ed",    BOOL,    CANSET,        o_edcompatible    },
  196.     { "equalprg",    "ep",    STR,    CANSET,        o_equalprg    },
  197.     { "errorbells",    "eb",    BOOL,    CANSET,        o_errorbells    },
  198. #ifndef CRUNCH
  199.     { "exrc",    "exrc",    BOOL,    CANSET,        o_exrc        },
  200. #endif
  201.     { "exrefresh",    "er",    BOOL,    CANSET,        o_exrefresh    },
  202.     { "flash",    "vbell",BOOL,    CANSET,        o_flash        },
  203. #ifndef NO_DIGRAPH
  204.     { "flipcase",    "fc",    STR,    CANSET,        o_flipcase    },
  205. #endif
  206. #ifndef NO_SENTENCE
  207.     { "hideformat",    "hf",    BOOL,    CANSET|MR,    o_hideformat    },
  208. #endif
  209.     { "ignorecase",    "ic",    BOOL,    CANSET,        o_ignorecase    },
  210. #ifndef NO_EXTENSIONS
  211.     { "inputmode",    "im",    BOOL,    CANSET,        o_inputmode    },
  212. #endif
  213.     { "keytime",    "kt",    NUM,    CANSET,        o_keytime    },
  214.     { "keywordprg",    "kp",    STR,    CANSET,        o_keywordprg    },
  215.     { "lines",    "ls",    NUM,    SET|NOSAVE|MR,    o_lines        },
  216.     { "list",    "li",    BOOL,    CANSET|MR,    o_list        },
  217. #ifndef NO_MAGIC
  218.     { "magic",    "ma",    BOOL,    CANSET,        o_magic        },
  219. #endif
  220. #ifndef NO_ERRLIST
  221.     { "make",    "mk",    STR,    CANSET,        o_make        },
  222. #endif
  223. #ifndef CRUNCH
  224.     { "mesg",    "me",    BOOL,    CANSET,        o_mesg        },
  225. #endif
  226. #ifndef NO_MODELINES
  227.     { "modelines",    "ml",    BOOL,    CANSET,        o_modelines    },
  228. #endif
  229. #ifndef CRUNCH
  230.     { "more",    "mo",    BOOL,    CANSET,        o_more        },
  231.     { "nearscroll",    "ns",    NUM,    CANSET,        o_nearscroll    },
  232.     { "newfile",    "new",    BOOL,    NOSAVE,        o_newfile    },
  233.     { "novice",    "nov",    BOOL,    CANSET,        o_novice    },
  234. #endif
  235.     { "number",    "nu",    BOOL,    CANSET|MR,    o_number    },
  236. #ifndef CRUNCH
  237.     { "optimize",    "opt",    BOOL,    CANSET,        o_optimize    },
  238. #endif
  239. #ifndef NO_SENTENCE
  240.     { "paragraphs",    "para",    STR,    CANSET,        o_paragraphs    },
  241. #endif
  242. #if MSDOS
  243.     { "pcbios",    "pc",    BOOL,    SET|NOSAVE,    o_pcbios    },
  244. #endif
  245. #ifndef CRUNCH
  246.     { "prompt",    "pr",    BOOL,    CANSET,        o_prompt    },
  247. #endif
  248.     { "readonly",    "ro",    BOOL,    CANSET,        o_readonly    },
  249.     { "remap",    "remap",BOOL,    CANSET,        o_remap        },
  250.     { "report",    "re",    NUM,    CANSET,        o_report    },
  251. #ifndef NO_EXTENSIONS
  252.     { "ruler",    "ru",    BOOL,    CANSET,        o_ruler        },
  253. #endif
  254.     { "scroll",    "sc",    NUM,    CANSET,        o_scroll    },
  255. #ifndef NO_SENTENCE
  256.     { "sections",    "sect",    STR,    CANSET,        o_sections    },
  257. #endif
  258.     { "shell",    "sh",    STR,    CANSET,        o_shell        },
  259. #ifndef NO_SHOWMATCH
  260.     { "showmatch",    "sm",    BOOL,    CANSET,        o_showmatch    },
  261. #endif
  262. #ifndef    NO_SHOWMODE
  263.     { "showmode",    "smd",    BOOL,    CANSET,        o_smd        },
  264. #endif
  265.     { "shiftwidth",    "sw",    NUM,    CANSET,        o_shiftwidth    },
  266.     { "sidescroll",    "ss",    NUM,    CANSET,        o_sidescroll    },
  267. #ifdef DEBUG
  268.     { "slowmacro",    "slow",    BOOL,    CANSET,        o_slowmacro    },
  269. #endif
  270.     { "sync",    "sy",    BOOL,    CANSET,        o_sync        },
  271.     { "tabstop",    "ts",    NUM,    CANSET|MR,    o_tabstop    },
  272. #ifndef CRUNCH
  273.     { "taglength",    "tl",    NUM,    CANSET,        o_taglength    },
  274.     { "tags",    "tag",    STR,    CANSET,        o_tags        },
  275. #endif
  276. #ifndef NO_TAGSTACK
  277.     { "tagstack",    "tgs",    BOOL,    CANSET,        o_tagstack    },
  278. #endif
  279.     { "term",    "te",    STR,    SET,        o_term        },
  280. #ifndef CRUNCH
  281.     { "terse",    "tr",    BOOL,    CANSET,        o_terse        },
  282.     { "timeout",    "to",    BOOL,    CANSET,        o_keytime    },
  283. #endif
  284. #if OS2
  285.     { "viomode",    "vm",    BOOL,    CANSET|MR,    o_viomode    },
  286. #endif
  287.     { "warn",    "wa",    BOOL,    CANSET,        o_warn        },
  288. #ifndef CRUNCH
  289.     { "window",    "wi",    NUM,    CANSET|MR,    o_window    },
  290.     { "wrapmargin",    "wm",    NUM,    CANSET,        o_wrapmargin    },
  291. #endif
  292.     { "wrapscan",    "ws",    BOOL,    CANSET,        o_wrapscan    },
  293. #ifndef CRUNCH
  294.     { "writeany",    "wr",    BOOL,    CANSET,        o_writeany    },
  295. #endif
  296.     { NULL, NULL, 0, CANSET, NULL }
  297. };
  298.  
  299.  
  300. /* This function initializes certain options from environment variables, etc. */
  301. void initopts()
  302. {
  303.     char    *val;
  304.     int    i;
  305. #if VMS
  306.     int    tty_ichan;
  307.     char    chbuf[12];
  308.     $DESCRIPTOR(inpdev,"TT");
  309.     int     err;
  310.     struct  terminfo {
  311.         unsigned class:8;
  312.         unsigned type:8;
  313.         unsigned pwidth:16;
  314.         unsigned tchar:22;
  315.         unsigned dummy:2;
  316.         unsigned plength:8;
  317.         unsigned xchar:32;
  318.     } tinfo;
  319.     struct iostab {
  320.         short int status;
  321.         short int terminator_offset;
  322.         short int terminator;
  323.         short int terminator_size;
  324.     } iostab;
  325. #endif